#include<iostream>
#include<math.h>
using std::endl;
using std::cout;
using std::string;
//图形
class Figure{
public:
    virtual string getName()const =0;
    virtual double getArea()const =0;
};
void display(Figure&fig){
    cout<<fig.getName()
        <<"的面积是 "
        <<fig.getArea()<<endl;
}

//Circle
class Circle
:public Figure{
public:
    Circle(double r)
    :circle_r(r){}
    virtual string getName()const override{
        return "Circle";
    }
    virtual double getArea()const override{
        return PI*circle_r*circle_r;
    }
private:
    double circle_r;
    static constexpr double PI = 3.1415926;
};

class Rectangle
:public Figure{
public:
    Rectangle(double length,double width)
    :_length(length)
    ,_width(width){}
    virtual string getName()const override{
        return "Rectangle";
    }
    virtual double getArea()const override{
        return _length*_width;
    }
private:
    double _length;
    double _width;
};

class triangle
:public Figure{

public: 
    triangle(double a,double b,double c)
    :_a(a)
    ,_b(b)
    ,_c(c)
    {}
    virtual string getName()const override{
        return "triangle";
    }
    virtual double getArea()const override{
        double p = (_a+_b+_c)/2;
        return sqrt(p*(p-_a)*(p-_b)*(p-_c));
    }

private:
    double _a;
    double _b;
    double _c;

};

void test0(){
    
    Circle c1(5);
    display(c1);
    cout<<endl;

    Rectangle R1(3,4);
    display(R1);
    cout<<endl;
    
    triangle t1(3,4,5);
    display(t1);
}

int main(void){
    test0();
    return 0;
}